import BaseApi from '@/api/baseApi';
import {ID} from '@/api/http';
import Department from '@/structure/department';
import DepartmentUser from '@/structure/departmentUser';

/**
 * 部门
 */
class DepartmentApi extends BaseApi<Department> {
  public getBase(): string {
    return 'user/user/department';
  }

  public getIdFieldName(): string {
    return 'departmentId';
  }

  /**
   * 获取部门树
   * @return 部门数
   */
  public tree(): Promise<Department[]> {
    return super.get0(`${this.getBase()}/tree`);
  }

  /**
   * 设置主管领导
   * @param data 部门用户信息
   * @return 响应
   */
  public setDirectorUser(data: DepartmentUser): Promise<void> {
    return super.post0(`${this.getBase()}/directorUser`, data);
  }

  /**
   * 移除主管领导
   * @param id 部门ID
   * @return 响应
   */
  public removeDirectorUser(id: ID): Promise<void> {
    return super.delete0(`${this.getBase()}/directorUser/${id}`);
  }

  /**
   * 设置分管领导
   * @param data 部门用户信息
   * @return 响应
   */
  public setChargeUser(data: DepartmentUser): Promise<void> {
    return super.post0(`${this.getBase()}/chargeUser`, data);
  }

  /**
   * 移除分管领导
   * @param id 部门ID
   * @return 响应
   */
  public removeChargeUser(id: ID): Promise<void> {
    return super.delete0(`${this.getBase()}/chargeUser/${id}`);
  }

  /**
   * 获取分配列表
   * @param id 部门ID
   * @return 职位ID列表
   */
  public getDistribution(id: ID): Promise<ID[]> {
    return super.get0(`${this.getBase()}/distribution/${id}`);
  }

  /**
   * 保存分配列表
   * @param id 部门ID
   * @param dutyIds 职位ID列表
   * @return 响应
   */
  public setDistribution(id: ID, dutyIds: ID[]): Promise<void> {
    return super.post0(`${this.getBase()}/distribution/${id}`, dutyIds);
  }
}

export default new DepartmentApi();
